package com.service.impl;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dao.AdminDao;
import com.entity.Admin;
import com.service.AdminService;
import com.util.MD5Util;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {
	@Autowired
	private AdminDao ad;

	// 管理员登录
	@Override
	public Admin adminLogin(Integer aid, String password) {
		return ad.adminLogin(aid, password);
	}

	// 管理员是否存在、根据id查询个人信息
	@Override
	public boolean isexistAdmin(Integer aid) {
		Admin isexistAdmin = ad.isexistAdmin(aid);
		if (isexistAdmin != null) {
			return true;
		}
		return false;
	}

	// 修改管理员密码
	@Override
	public boolean updateAdminpassword(Integer aid, String password) {
		System.out.println("aid:" + aid + "/" + "password" + password);
		Admin isexistAdmin = ad.isexistAdmin(aid);
		System.out.println(isexistAdmin);
		if (isexistAdmin != null) {
			ad.updateAdminpassword(aid, password);
			return true;
		} else {
			return false;
		}
	}

	// 退出登录
	@Override
	public int exitAdmin(Integer aid) {
		return ad.exitAdmin(aid);
	}

	@Override
	public Admin findAdminInfoById(Integer aid) {
		return ad.findAdminInfoById(aid);
	}

	// 修改个人信息
	@Override
	public boolean updateAdminInfo(Admin admin) {
		return ad.updateAdminInfo(admin);
		// Admin isexistAdmin = ad.isexistAdmin(admin.getAid());
		// if (isexistAdmin != null) {
		// ad.updateAdminInfo(admin);
		// return true;
		// }else {
		// return false;
		// }
	}

}
